using System;
using Sirenix.OdinInspector;
using UnityEngine;

/// <summary>
/// 节点属性
/// </summary>
[Serializable]
public class NodeProperty
{
    [LabelText("属性名称"), OnValueChanged("stringOnly")]
    public string PropName;

    [LabelText("描述（选填）")] public string Desc = "";

    [LabelText("默认属性（输入 Param）"), ShowIf("IsString")]
    public string paramString = "";

    [LabelText("默认属性（输入 Param）"), ShowIf("IsVector2")]
    public Vector2 paramVec2 = Vector2.zero;

    [LabelText("默认属性（输入 Param）"), ShowIf("IsInt")]
    public int paramInt = 0;

    [LabelText("默认属性（输入 Param）"), ShowIf("IsFloat")]
    public float paramFloat = 0;

    [LabelText("默认属性（输入 Param）"), ShowIf("IsBoolean")]
    public bool paramBool = false;

    [LabelText("默认属性（输入 Param）"), ShowIf("IsArrayInt")]
    public int[] paramInts = new int[] { };

    [LabelText("默认属性（输入 Param）"), ShowIf("IsArrayString")]
    public string[] paramStrs = new string[] { };

    public NodePropertyType Type = NodePropertyType.Int;

    public void stringOnly(string v)
    {
        PropName = NodeMethodUtil.StringOnly(v);
    }

    public bool HasDefault()
    {
        return Type != NodePropertyType.ActorID ||
               Type != NodePropertyType.Node;
    }

    public bool IsString()
    {
        return HasDefault() &&
               (Type > NodePropertyType.Line ||
                Type == NodePropertyType.String ||
                Type == NodePropertyType.AudioPlayData);
    }

    public bool IsInt()
    {
        return HasDefault() &&
               (Type == NodePropertyType.Int ||
                Type == NodePropertyType.Direction);
    }

    public bool IsFloat()
    {
        return HasDefault() &&
               Type == NodePropertyType.Float;
    }

    public bool IsArrayString()
    {
        return HasDefault() &&
               Type == NodePropertyType.ArrayString;
    }

    public bool IsArrayInt()
    {
        return HasDefault() &&
               Type == NodePropertyType.ArrayInt;
    }

    public bool IsBoolean()
    {
        return HasDefault() &&
               Type == NodePropertyType.Boolean;
    }

    public bool IsVector2()
    {
        return HasDefault() &&
               Type == NodePropertyType.Vector2;
    }
}